The syntax for writing a loop in pseudo code typically involves using keywords like "for", "while", or "do-while" to indicate the type of loop, followed by the loop condition and the code block to be executed within the loop.
Pseudo code does not have key words, you make it up, that's why it is pseudo.
loop within in a loop is called for next loop
do { //statements }while(condition); The statements inside the block get executed at-least once, no matter what condition you have placed. Only from the 2nd time the condition is checked, simply because the condition is at the last. for(initialization; condition; updation) { //statements } Here the statements don't get executed even once if the condition fails initially. The condition is at the entry itself.
for(i=0;i<=0;i++)
loop i from 0 to num check if num mod i equals 0breakelsesum = sum + numend the loopprint the sum
The do-while loop is designed specifically for such situations, where you want the loop to execute once irrespective of the loop expression. The loop would execute once and then terminate because, the loop controlling expression is false. If you note the syntax properly do { ... ... ... } while(condition) The condition is executed only after one iteration of the loop and hence the code would execute once irrespective of the loop expression result.
Yes. while loop consist of only condition statement to make for loop look as while loop we can use syntax shown below: for(;condition;) eg: for(;i<=n;)
In the "old days" before computers had vdu's, it was amusing to generate shapes on the printer. One option for a right angle might be, in pseudo code, For n= 1 to 15 step 1 Print "*"; carriage return Loop Print "";"";"******"
No. A syntax error is a statement that fails to compile. Infinite loops are simply loops for which the number of iterations is unknown. However, all loops, whether counted loops or infinite loops, must have a reachable exit condition. If a loop does not have a reachable exit condition then it is a logic error, not a syntax error.
You can use any number of if staments within a for-loop, eg: for (i=0; i<10; ++i) { if (i=1) printf ("%d=1\n",i); }
The while loop in vb.net uses the syntax form which provides a way to continue iterating while one or more conditions are true.
The FOR loop syntax is as follows for(counter initiation/declaration; condition; counter increment){ code.... } example: for(int i = 0; i < 10; i++){ System.out.println(i); } In the above code the variable i is the loop counter. We have initiated in the first part of the for loop. The second part is the condition. The loop would be executed until the value of i is less than 10. The third is the loop increment to ensure that the value of i would not remain the same causing an infinite loop. for(int i = 0; i < 10; ){ System.out.println(i); } The above for loop usage is an infinite loop because the value of i would never change and the loop would go on forever. for(int i = 0; i < 10; ){ System.out.println(i); i++; } You can even opt to have the loop counter incremented inside the loop construct. This would make it similar to a while loop. but anyways the purpose of the increment remains the same.