Group Abstract Group Abstract

Message Boards Message Boards

0
|
6.9K Views
|
5 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Can somebody help me on building up my LOOP structure?

Posted 12 years ago

Can somebody help me on finalizing my loop structure? I am looking for a loop that will BREAK when I get an integer results and print that result

I tried that one but it does not work Can you improve it?

Do[If[IntegerQ[107/i],Print[107/i],{i,2,8,2}]

Thanks for your help

Louis

POSTED BY: Louis Piche
5 Replies
Posted 12 years ago

IF ANYBODY CAN HELP ME ON. THANKS.

Sir David Reiss, I have to thank you very much for your response. It works as required.

<a href="mailto:Catch@Do[If[IntegerQ[14291/i]">Catch@Do[If[IntegerQ[14291/i], Throw[{i, 14291/i}]], {i, 2, 14291}]

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, ___________________

POSTED BY: Louis Piche
POSTED BY: David Reiss

You need a right bracket to close the If statement.

Do[If[IntegerQ[107/i], Print[107/i]], {i, 1, 8}]

107

POSTED BY: Frank Kampas
Posted 12 years ago

Sir,

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.

Catch@Do[If[IntegerQ[14291/i], Throw[{i, 14291/i}]], {i, 2, 14291}]

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.

Thanks for your reply, Have a good day

POSTED BY: Louis Piche
Posted 9 years ago

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 ____________

POSTED BY: Louis Piche
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard