Egypt › Secondary › First Secondary Grade › Programming and Artificial Intelligence › Unit ١٢: Programming

Lesson ٣: Programming Basics ٢

First Secondary GradeProgramming and Artificial IntelligenceSecond Termالدرس ٣٣٠ دقيقة

فيديو الشرح

الفيديو قيد الإنتاج، وسيظهر هنا فور اعتماده.

ماذا ستتعلم؟

اختبر استعدادك أولًا

١. In the question "What is a loop?" the options are: ١) A structure that repeats a group of steps ٢) A single step ٣) A variable type ٤) A screen part. What is the number of the correct answer?
٢. In the question "When do we use a for loop?" the options are: ١) When we never repeat ٢) When we know how many repetitions we want ٣) When we know nothing ٤) Only for pictures. What is the number of the correct answer?
٣. In the question "When do we use a while loop?" the options are: ١) Only for colors ٢) When no condition exists ٣) When we repeat while a condition is true ٤) Never. What is the number of the correct answer?

الشرح خطوة بخطوة

Level ١: We explore together

Lesson topic: Programming Basics ٢. In the second programming lesson we meet loops, which repeat work without writing it many times.

The story: A loop repeats a group of steps while a condition is true or for a known number of times. A for loop is used when we know how many times we want to repeat, like printing five lines. A while loop repeats as long as a condition stays true, like asking for a password until it is correct. We must make sure a loop can end, otherwise the program runs forever and freezes. In this lesson we learn for loops, while loops, and how to avoid endless loops.

أخطاء شائعة وتصحيحها

أمثلة محلولة متدرجة

Easy · مثال ١

What is a loop?

  1. نقرأ السؤال معًا بهدوء.
  2. Repeat steps.
الإجابة: A structure that repeats a group of steps
Easy · مثال ٢

Which loop fits: print the numbers ١ to ١٠٠?

  1. نقرأ السؤال معًا بهدوء.
  2. Known count.
الإجابة: A for loop
Easy · مثال ٣

Which loop fits: keep asking until the answer is correct?

  1. نقرأ السؤال معًا بهدوء.
  2. Unknown count, condition.
الإجابة: A while loop
Medium · مثال ٤

Write in words a for loop that prints your name five times.

  1. نقرأ السؤال معًا بهدوء.
  2. Count to five.
الإجابة: For each number from ١ to ٥: print my name
Medium · مثال ٥

A while loop says: while hungry, eat. When does it stop?

  1. نقرأ السؤال معًا بهدوء.
  2. When the condition breaks.
الإجابة: It stops when hungry becomes false, that is when the person is no longer hungry
Medium · مثال ٦

Find the bug: counter = ١; while counter < ٥: print(counter). How do we fix it?

  1. نقرأ السؤال معًا بهدوء.
  2. Something must change.
الإجابة: The counter never changes inside the loop, so the loop never ends; fix: increase counter by ١ inside the loop
Medium · مثال ٧

Compare for and while loops in one sentence each.

  1. نقرأ السؤال معًا بهدوء.
  2. Known count versus condition.
الإجابة: A for loop repeats a known number of times; a while loop repeats as long as its condition stays true
Advanced · مثال ٨

Design in words a loop that adds the numbers from ١ to ١٠ and prints the total.

  1. نقرأ السؤال معًا بهدوء.
  2. A total variable plus a counter.
الإجابة: Set total to ٠; for each number from ١ to ١٠ add the number to total; after the loop print total (the result is ٥٥)
Error analysis · مثال ٩

Your friend says: "A while loop always runs exactly ten times." Is this correct?

  1. نقرأ السؤال معًا بهدوء.
  2. What controls repetition?
الإجابة: Wrong, a while loop runs as long as its condition is true; the number of times depends on the condition

الخريطة الذهنية

Programming Basics ٢Unit ١٢: Programming
▼
A structure that repeats a group of stepsWhat is a loop?
When we know how many repetitions we wantWhen do we use a for loop?
When we repeat while a condition is trueFrom the lesson questions
Print the numbers from ١ to ٥Give an example of a for loop in words.

إنفوجرافيك: Lesson map: words of the day

Lesson map: words of the day
اضغط على أي صف لترى الفكرة.
The key ideas of the lesson in order
We review the questions after one day, then after three days

تدريبات متنوعة مع الإجابات والتفسير

اكتب الإجابة أو اختر ثم اضغط. بعد كل سؤال يظهر الحل مع التفسير.

A) I choose the answer

١. From the lesson explanation: A while loop repeats as long as a condition stays true, like asking for a password until it is correct.
٢. Which question has the answer "When we repeat while a condition is true"?
٣. The answer "When we know how many repetitions we want" to the question "When do we use a for loop?" is correct.
٤. The answer "A cable" to the question "What is a loop counter?" is correct.
٥. From the lesson explanation: What is an endless (infinite) loop?
٦. Which question has the answer "A variable that counts how many times the loop has repeated"?
٧. The answer "A screen part" to the question "What is a loop?" is correct.
٨. The answer "A fast loop" to the question "What is an endless (infinite) loop?" is correct.

B) I practice and answer

١. From the lesson explanation: Give an example of a while loop in words.
٢. From the lesson explanation: When do we use a while loop?
٣. From the lesson explanation: A loop repeats a group of steps while a condition is true or for a known number of times.
٤. The answer "Add more repetitions" to the question "How do we stop an infinite loop?" is correct.
٥. The answer "Wait forever" to the question "How do we stop an infinite loop?" is correct.
٦. The answer "Only for pictures" to the question "When do we use a for loop?" is correct.
٧. From the lesson explanation: In this lesson we learn for loops, while loops, and how to avoid endless loops.
٨. The answer "A loop with no body" to the question "What is an endless (infinite) loop?" is correct.

C) I review and play

١. The answer "Draw a circle once" to the question "Give an example of a while loop in words." is correct.
٢. Which question has the answer "Keep asking for the password until it is correct"?
٣. From the lesson explanation: What is a loop counter?
٤. From the lesson explanation: A for loop is used when we know how many times we want to repeat, like printing five lines.
٥. The answer "They are slower" to the question "Why do loops save effort?" is correct.
٦. The answer "١٠٠" to the question "In "repeat ١٠ times: clap", how many claps happen?" is correct.
٧. From the lesson explanation: What is a loop?
٨. The answer "When we repeat while a condition is true" to the question "When do we use a while loop?" is correct.

ملخص صوتي وقارئ الدرس

قارئ تجريبي يعمل بصوت جهازك (مجاني). ليس تسجيلًا احترافيًا، وجودة الصوت العربي تختلف من جهاز لآخر. التسجيل الصوتي الاحترافي لم يُنتج بعد.

Lesson topic: Programming Basics ٢. In the second programming lesson we meet loops, which repeat work without writing it many times.

We review the key points of the lesson: What is a loop? -> A structure that repeats a group of steps; When do we use a for loop? -> When we know how many repetitions we want.

We apply what we learned by answering these questions: What is a loop? -> A structure that repeats a group of steps; When do we use a for loop? -> When we know how many repetitions we want; When do we use a while loop? -> When we repeat while a condition is true.

مسار المراجعة للامتحان

  1. Day one (١٠ minutes): We read levels ١ to ٣ together, then solve exercises (A).
  2. Day two (١٠ minutes): We play the level ٤ games and solve exercises (B).
  3. Day three (١٠ minutes): Exercises (C), then the Level One test.
  4. Before the school exam: We repeat the Level Three test and look at the common mistakes.

اختبارات بثلاثة مستويات

Level One Test: The Basics

٨ أسئلة. اجب ثم اضغط «أنهِ الاختبار» لترى درجتك.

١. The answer "Delete the program" to the question "Give an example of a for loop in words." is correct.
٢. From the lesson explanation: We must make sure a loop can end, otherwise the program runs forever and freezes.
٣. Which question has the answer "When we know how many repetitions we want"?
٤. Which question has the answer "Print the numbers from ١ to ٥"?
٥. The answer "Make sure the condition changes so it can become false" to the question "How do we stop an infinite loop?" is correct.
٦. The answer "Keep asking for the password until it is correct" to the question "Give an example of a while loop in words." is correct.
٧. The answer "A printer" to the question "What is a loop counter?" is correct.
٨. From the lesson explanation: Why do loops save effort?

المصادر والحقوق

رمز QR هذه الصفحة. يفتح درس «Lesson ٣: Programming Basics ٢» نفسه.