0Pricing
Arduino & IoT Academy · Урок

loop() выполняется постоянно

Сердцебиение программы, бесконечно повторяющее Вашу логику

«loop() выполняется постоянно» — бесплатный урок Arduino & IoT Academy на CoddyKit. Это урок 2 из 4. Ты можешь прочитать весь урок бесплатно ниже — а потом практиковать его прямо в браузере с встроенным редактором кода и ИИ-репетитором 24/7. Это часть пути обучения Arduino & IoT Academy, и твой прогресс синхронизируется между веб-версией и приложением CoddyKit. Курс Arduino & IoT Academy содержит 4 уроков всего.

Части этого урока еще не переведены и отображаются на английском.

The Heartbeat

After setup finishes, the second block takes over. Meet loop(), the part of your sketch that never stops running. 🔁

Runs Over and Over

The key idea: loop() repeats endlessly. The board runs it, reaches the bottom, then jumps straight back to the top.

What loop() Looks Like

Just like setup, it returns void and holds your code inside curly braces. This is where your device's behavior lives.

void loop() {
  // repeating code goes here
}

Setup First, Then Loop

Order matters. The board runs setup() once, then hands control to loop forever. They are partners, not rivals.

A Blinking Example

Inside loop you might turn an LED on, wait, then off. The board repeats this, so the light blinks again and again.

void loop() {
  digitalWrite(13, HIGH);
  delay(500);
  digitalWrite(13, LOW);
  delay(500);
}

Reading Inputs Live

Because loop runs constantly, it can check sensors thousands of times a second. That is how your device stays responsive to the world.

No while(true) Needed

You do not write your own forever-loop. Arduino already repeats loop() for you, so just describe one pass of behavior.

It Never Truly Ends

loop only stops when power is cut or the board resets. As long as it has power, your loop() keeps cycling.

Order Inside Matters

Lines in loop run top to bottom each pass. Rearranging them changes the sequence of actions your device performs.

Empty Loop Is Allowed

An empty loop() compiles fine, but your device just sits idle. The braces are still required even with nothing inside.

void loop() {
}

Together They Are a Sketch

Every Arduino program needs both blocks: setup() to prepare and loop() to act. With these two, you can build anything.

void setup() {
}
void loop() {
}

Quick Check

Let's check how loop() behaves.

Recap: loop()

You learned that loop() runs forever after setup, repeating top to bottom. It is where your device senses and reacts on every pass. 🎉

Часто задаваемые вопросы

Урок «loop() выполняется постоянно» бесплатный?

Да — полный текст урока «loop() выполняется постоянно» бесплатно доступен здесь в веб-версии. Чтобы практиковать его интерактивно (встроенный редактор кода и ИИ-репетитор 24/7) и разблокировать остальной курс Arduino & IoT Academy, подпишись на CoddyKit PRO. Курс Arduino & IoT Academy содержит 4 уроков всего.

Чему я научусь в уроке «loop() выполняется постоянно»?

Сердцебиение программы, бесконечно повторяющее Вашу логику Ты практикуешь Arduino & IoT Academy с помощью реального кода, который запускаешь прямо в браузере, и ИИ-репетитор 24/7 отвечает на твои вопросы во время урока.

Нужен ли мне опыт, чтобы начать Arduino & IoT Academy?

Предыдущий опыт не требуется. Arduino & IoT Academy на CoddyKit структурирован для всех уровней — от новичков до продвинутых, поэтому ты можешь начать отсюда или с самого начала и учиться в своем темпе. Это урок 2 из 4.

Сколько времени занимает урок «loop() выполняется постоянно»?

Большинство уроков CoddyKit занимают около 5–10 минут. Каждый из них компактный и интерактивный, поэтому ты постоянно делаешь прогресс и продолжаешь с того же места в веб-версии и приложении.

Можно ли писать и запускать код в этом уроке Arduino & IoT Academy?

Да. Каждый урок Arduino & IoT Academy включает встроенный редактор кода, поэтому ты пишешь и запускаешь реальный код прямо в браузере и получаешь моментальную обратную связь от AI — локальная установка не требуется.

Все уроки этого курса

  1. setup() выполняется один раз
  2. loop() выполняется постоянно
  3. Комментарии и аккуратные скетчи
  4. Ошибки компиляции и их чтение
← Назад к Arduino & IoT Academy