Artwork

Content provided by HPR Volunteer and Hacker Public Radio. All podcast content including episodes, graphics, and podcast descriptions are uploaded and provided directly by HPR Volunteer and Hacker Public Radio or their podcast platform partner. If you believe someone is using your copyrighted work without your permission, you can follow the process outlined here https://player.fm/legal.
Player FM - Podcast App
Go offline with the Player FM app!

HPR2438: Gnu Awk - Part 8

 
Share
 

Manage episode 192970883 series 108988
Content provided by HPR Volunteer and Hacker Public Radio. All podcast content including episodes, graphics, and podcast descriptions are uploaded and provided directly by HPR Volunteer and Hacker Public Radio or their podcast platform partner. If you believe someone is using your copyrighted work without your permission, you can follow the process outlined here https://player.fm/legal.

Gnu Awk - Part 8

Introduction

This is the eighth episode of the "Learning Awk" series that b-yeezi and I are doing.

Recap of the last episode

  • The while loop: tests a condition and performs commands while the test returns true

  • The do while loop: performs commands after the do, then tests afterwards, repeating the commands while the test is true.

  • The for loop (type 1): initialises a variable, performs a test, and increments the variable all together, performing commands while the test is true.

  • The for loop (type 2): sets a variable to successive indices of an array, preforming a collection of commands for each index.

These types of loops were demonstrated by examples in the last episode.

Note that the example for 'do while' was an infinite loop (perhaps as a test of the alertness of the audience!):

#!/usr/bin/awk -f BEGIN { i=2; do { print "The square of ", i, " is ", i*i; i = i + 1 } while (i != 2) exit; }

The condition in the while is always true:

The square of 2 is 4 The square of 3 is 9 The square of 4 is 16 The square of 5 is 25 The square of 6 is 36 The square of 7 is 49 The square of 8 is 64 The square of 9 is 81 The square of 10 is 100 ... The square of 1269630 is 1611960336900 The square of 1269631 is 1611962876161 The square of 1269632 is 1611965415424 The square of 1269633 is 1611967954689 The square of 1269634 is 1611970493956 ...

The variable i is set to 2, the print is executed, then i is set to 3. The test "i != 2" is true and will be ad infinitum.

Some more statements

We will come back to loops later in this episode, but first this seems like a good point to describe another statement: the switch statement.

Long notes

The notes for rest of this episode are available here.

Links

  continue reading

4104 episodes

Artwork

HPR2438: Gnu Awk - Part 8

Hacker Public Radio

23 subscribers

published

iconShare
 
Manage episode 192970883 series 108988
Content provided by HPR Volunteer and Hacker Public Radio. All podcast content including episodes, graphics, and podcast descriptions are uploaded and provided directly by HPR Volunteer and Hacker Public Radio or their podcast platform partner. If you believe someone is using your copyrighted work without your permission, you can follow the process outlined here https://player.fm/legal.

Gnu Awk - Part 8

Introduction

This is the eighth episode of the "Learning Awk" series that b-yeezi and I are doing.

Recap of the last episode

  • The while loop: tests a condition and performs commands while the test returns true

  • The do while loop: performs commands after the do, then tests afterwards, repeating the commands while the test is true.

  • The for loop (type 1): initialises a variable, performs a test, and increments the variable all together, performing commands while the test is true.

  • The for loop (type 2): sets a variable to successive indices of an array, preforming a collection of commands for each index.

These types of loops were demonstrated by examples in the last episode.

Note that the example for 'do while' was an infinite loop (perhaps as a test of the alertness of the audience!):

#!/usr/bin/awk -f BEGIN { i=2; do { print "The square of ", i, " is ", i*i; i = i + 1 } while (i != 2) exit; }

The condition in the while is always true:

The square of 2 is 4 The square of 3 is 9 The square of 4 is 16 The square of 5 is 25 The square of 6 is 36 The square of 7 is 49 The square of 8 is 64 The square of 9 is 81 The square of 10 is 100 ... The square of 1269630 is 1611960336900 The square of 1269631 is 1611962876161 The square of 1269632 is 1611965415424 The square of 1269633 is 1611967954689 The square of 1269634 is 1611970493956 ...

The variable i is set to 2, the print is executed, then i is set to 3. The test "i != 2" is true and will be ad infinitum.

Some more statements

We will come back to loops later in this episode, but first this seems like a good point to describe another statement: the switch statement.

Long notes

The notes for rest of this episode are available here.

Links

  continue reading

4104 episodes

All episodes

×
 
Loading …

Welcome to Player FM!

Player FM is scanning the web for high-quality podcasts for you to enjoy right now. It's the best podcast app and works on Android, iPhone, and the web. Signup to sync subscriptions across devices.

 

Quick Reference Guide