ConceptStep · learning platform for computer science

The WHILE loop

C programming · Lesson

C · lesson 8 / 27

The WHILE loop

Follow a condition-controlled loop and observe how state changes toward termination.

1 · Observe and predict

The concept

while checks before each iteration; updating i lets the loop terminate.

Mental model:

i = 1 → while i <= limit → output i → i = i + 1 → test

2 · Flowchart First

Follow the same algorithm as a flowchart

Use Start and Step: when the active block changes, ConceptStep also highlights the C lines representing that same step.

Loading flowchart…
3 · Flowchart ↔ C · Run in Page

Lab 1 — Run the example program

Run C executes only the example shown on the left, using stdin on the right. The coding challenge below has a separate editor and test button.

WHILE: count to the limit Start the flowchart to synchronize the code
                        1#include <stdio.h>
                        2 
                        3int main(void)
                        4{
                        5    int limite;
                        6    scanf("%d", &limite);
                        7    int i = 1;
                        8 
                        9    while (i <= limite)
                        10    {
                        11        printf("%d\n", i);
                        12        i = i + 1;
                        13    }
                        14 
                        15    return 0;
                        16}
Ready. Make a prediction before running.

                    
                

Lab 2 — Coding challenge: write your code — Sum from 1 to N

Read nonnegative N and print the sum from 1 to N using a loop.

This is a different program from lab 1. Complete the starter code: Check all test cases compiles this editor and tests every input, including boundary cases.

4 · Guided practice

Check your prediction

If limit = 4, how many iterations run?

Challenge 1 / 5 · Understanding

Progress: 0 / 5 · correct: 0

Your competency map

What you need to know for The WHILE loop

ConceptStep separates what is required from what is recommended or useful as reinforcement. Only required prerequisites block your progress.

Current topic Strong skill Review due Needs reinforcement To be mastered Optional support

Relationships: solid line = required · dashed line = recommended · dotted line = reinforcement.

GUIDED LEARNING PATHS

Want to choose the next skill to develop?