Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
C shell
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Control structures === The C shell provides control structures for both [[Conditional (programming)|condition-testing]] and [[iteration]]. The condition-testing control structures are the if and switch statements. The iteration control structures are the while, foreach and repeat statements. ==== if statement ==== There are two forms of the [[if statement]]. The short form is typed on a single line but can specify only a single command if the expression is true. <syntaxhighlight lang="csh">if ( expression ) command</syntaxhighlight> The long form uses then, else and endif keywords to allow for blocks of commands to be nested inside the condition. <syntaxhighlight lang="csh"> if ( expression1 ) then commands else if ( expression2 ) then commands ... else commands endif </syntaxhighlight> If the else and if keywords appear on the same line, csh chains, rather than nests them; the block is terminated with a single endif. ==== switch statement ==== The switch statement compares a string against a list of patterns, which may contain wildcard characters. If nothing matches, the default action, if there is one, is taken. <syntaxhighlight lang="csh"> switch ( string ) case pattern1: commands breaksw case pattern2: commands breaksw ... default: commands breaksw endsw </syntaxhighlight> ==== while statement ==== The [[While loop|while statement]] evaluates an expression. If it is true, the shell runs the nested commands and then repeats for as long as the expression remains true. <syntaxhighlight lang="csh"> while ( expression ) commands end </syntaxhighlight> ==== foreach statement ==== The foreach statement takes a list of values, usually a list of filenames produced by wildcarding, and then for each, sets the loop variable to that value and runs the nested commands. <syntaxhighlight lang="csh"> foreach loop-variable ( list-of-values ) commands end </syntaxhighlight> ==== repeat statement ==== The repeat statement repeats a single command an integral number of times. <syntaxhighlight lang="csh">repeat integer command</syntaxhighlight>
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
C shell
(section)
Add topic