Save this video free

Lecture 13: Loops

Burton Ma · 47:52 · Watch on YouTube

Part of Queen's University CISC220. See all 23 lectures and search them

These notes were made with YouTube Collector. Paste any YouTube link and get the same: a summary, chapters and a searchable transcript.

Overview

Burton Ma explains Bash's `while`, `until`, for-each, and C-style counting loops, emphasizing that loop conditions use command exit statuses and that quoting controls how values are split. Examples include countdowns, the Collatz conjecture, safe processing of script arguments and files, and an introduction to Bash functions and their positional parameters.

Key takeaways

Chapters

0:00 Bash `while` and `until` Loops Use Command Exit Statuses
6:23 Counting Down and the Collatz Conjecture
9:25 Validating Input and Implementing Collatz in Bash
16:01 Bash For-Each Loops and Word Splitting
19:40 Glob, Brace, and Command Expansions as Loop Inputs
24:53 C-Style Counting Loops and Their Syntax
27:00 Processing Script Arguments with `"$@"` and `shift`
34:03 Reading and Splitting File Lines with Bash `read`
38:51 Declaring and Calling Bash Functions
43:03 Function Arguments and Script Positional Parameters

Keep these chapters and the full searchable transcript in your own library.

Transcript excerpt

0:01 Right. Good afternoon everybody. Uh the topic of today's lecture um is uh loops. Um so from your previous programming courses in Python and Java uh you would have seen a for loop almost certainly. Um so you would have seen two versions of a for loop. You would have seen a for each loop which you would have seen in Python. Uh and you would have seen a counting style loop which you would have seen in Java. Uh, and of course in Python, you emulate a counting style loop using a for each loop. Uh, depending on exactly what you covered in your Java course, you might have seen a while loop. Uh, and you probably did not see a dowh loop. Um, which is fine. So, bash has a for loop. Uh, it looks a lot like

0:50 a for each loop. So, it looks similar to Python's for loop. Uh, bash also has a counting style loop. So, similar to the Java style loop, here it says C style, but the Java inherited its syntax from C. U bash has a while loop. So, while some condition is true, loop. Uh, and it also has an until loop. So, until some condition is true, loop, right? And until is a bit unusual. Um, uh, it's the only programming language I know of that has one. Um there are probably others though that do have an until loop. Uh Java also has a dowhile loop. Uh but bash doesn't have one of those. Okay. So just like in Java or uh Python, break and continue are uh the usual

1:38 keywords inside of a loop, right? So break will break out of a loop. Uh continue will stop the current loop iteration and go to the next loop iteration just like it does in Python

This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.

In this course

Related notes

Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Burton Ma.

Want the full transcript?

Save this video in YouTube Collector to get its complete searchable transcript, your own AI summaries, and a library that keeps every video you collect in one place.