loop() は繰り返し実行される
ロジックを無限に繰り返す心拍部です
「loop() は繰り返し実行される」はCoddyKit上の無料Arduino & IoT Academyレッスンです。 これはレッスン2/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これは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時間対応のAIチューター)、Arduino & IoT Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Arduino & IoT Academyコースには全4レッスンが含まれています。
「loop() は繰り返し実行される」で何を学びますか?
ロジックを無限に繰り返す心拍部です ブラウザで直接実行するハンズオンコードでArduino & IoT Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Arduino & IoT Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのArduino & IoT Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン2/4です。
「loop() は繰り返し実行される」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このArduino & IoT Academyレッスンでコードを書いて実行できますか?
はい。すべてのArduino & IoT Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- setup() は 1 回だけ実行される
- loop() は繰り返し実行される
- コメントと読みやすいスケッチ
- コンパイルエラーと読み方