Programming Question Help

Discussion in 'Programmer's Corner' started by Ricky Sum, Jun 30, 2016.

  1. Ricky Sum

    Thread Starter New Member

    May 6, 2016
    13
    0

    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)
     
  2. AlbertHall

    Well-Known Member

    Jun 4, 2014
    1,889
    375
    Sounds good to me.
    But then I'm a self-taught programmer...
     
  3. Ricky Sum

    Thread Starter New Member

    May 6, 2016
    13
    0
    ok. thank
     
  4. ci139

    Member

    Jul 11, 2016
    341
    38
    (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
     
  5. ci139

    Member

    Jul 11, 2016
    341
    38
    correction:
    (2) JZ (0) // --- Causes infinite loop if a equals to b equals to Zero
     
  6. BR-549

    Well-Known Member

    Sep 22, 2013
    1,981
    388
    Somebodies running out of ink.
     
  7. ci139

    Member

    Jul 11, 2016
    341
    38
    Hi! i confess i'm a squid :oops:
    :confused: but i still find this question confusing
     
  8. naickej4

    Member

    Jul 12, 2015
    182
    2
    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.
     
  9. jpanhalt

    AAC Fanatic!

    Jan 18, 2008
    5,675
    899
    Why has this thread not been moved to homework?
     
  10. naickej4

    Member

    Jul 12, 2015
    182
    2
    Hi Sir, I'm not sure. I think a moderator only has access to more these threads across to "homework" forum.
     
Loading...