Note that the approach does not actually break when the value is reached (and in the original case illustrated it will never result in a returned value since 107 is not even). The Do loop will go until the end whether or not the value in the first argument of the If statement is satisfied. An approach like this (without a Print statement since you want a returned value rather than a byproduct of the Do loop as a printed statement) will satisfy what you are looking for (using 14291 as a test case and returning both the value of i where it achieves its IntegerQ requirement and the result of that requirement):
And if you actually wanted to go through the whole Do loop and get all instances where the If statement evaluated to True you could use Reap and Sow like this:
But now, as you specified, It would be better to insert a BREAK as soon as the loop encounters a suitable factor and Print the results. But, when I say PRINT, I would like to be able to Print the results from my printer machine too not only Print on the Wolfram screen.
There is something more I would be pleased. I would like to see and print on the screen and on my printing machine the results of all divisions made into the loop keeping a certain number of decimals after the point (maybe 5 decimals when it is the case). As sample, 14291/2 = 7145.5; 14291/3=4763.66666.
CAN YOU HELP ME ON THOSE TWO QUESTIONS?
And, by the way, do you know a reference book when I could find out Wolfram programming language practice exercices of all kink?
Waiting for your reply,
Thanks so much for your help,
Thanks. You are right. I forgot a bracket for the If.
Can you help me on the following (I got this from David Reiss which was a very good response)?
I would like to insert a BREAK as soon as a first factor is found out, print on the screen and also print the result from my printing machine.
ALSO,
From a new command line, to get all the results of the divisions along with decimals (maximum of 5 decimals) and print on the screen and from my printing machine.
Any can help,
Sir,
Can you help me on?
The input is:
Do[If[IntegerQ[121/i], Print[i]],{i,2,11}]
The output will be:
11
BUT
I would like to get an output such as “No Solution” if I have the following
Input
Do[If[IntegerQ[121/i], Print[i]],{i,2,7}]
I want to print an output : “No Solution”
How and where to insert the code?
Thanks for your help