Programming Question Help

Thread Starter

Ricky Sum

Joined May 6, 2016
13

  1. Below is the question and I have answer but can advise is correct.

    Explain the three statements needed to to formulate a for loop.
Answer:

  1. Something to do before starting

  2. A test to perform as long as it’s true, keep looping

  3. Something to do after each loop (increase a variable)
 

ci139

Joined Jul 11, 2016
1,989
(1) Something to do before starting : allocate mem for a loop counter variable initialize it´s value (also the tracking variables if any needed)

(2) A test to perform as long as it’s true, keep looping + (uptate "tracking variables" if such is required here - such as array index offsets , any other values yet the any other values depend on) add another test to pass program control to possible error handles (including the infinite loop condition check) (division by zero is best to predict and avoid programmatically rather than handle when it occurs)

(3) Something to do after each loop (increase a variable) + (uptate "tracking variables" if such is requred here)

??? it sounds weird ? Explain in(or with) 3 ... or what are the 3 statements ... ???

(0) Check the Loop condition if it's valid do the (1) otherwise do the (3) // ((such as CMP a,b))
(1) Do the Loop sub-routine // ((such as NOP))
(2) Return/Go to (0) // ((such as JZ))
(3) Exit Loop

? Three ? Like that ? What's the question

(1) Do the Loop sub-routine // --- such as NOP
(2) Check the Loop condition // such as CMP a,b
(3) if it's valid Go to (1) otherwise goto (?Next) // --- such as JZ
(?Next)

? Three ? Like that ? How many statemants Minimum form the loop ? What it has to do with anything

(0) NOP
(1) CMP a,b
(2) JZ (0) // --- Causes infinite loop if a equals to b
 

naickej4

Joined Jul 12, 2015
206

  1. Below is the question and I have answer but can advise is correct.

    Explain the three statements needed to to formulate a for loop.
Answer:

  1. Something to do before starting

  2. A test to perform as long as it’s true, keep looping

  3. Something to do after each loop (increase a variable)
Hello,
Yes your answer is correct.
1. Initialize, add a starting value to the variable used in your test condition.
2. Test condition. Can also be boolean operations.
3. Increment or decrement a variable that is used in the testing condition. (This will proceed with the loop or terminate the loop depending on the test conditions)

Thank you.
 
Top