Electronics Circuits & Tutorials - Electronics Hobby Projects - A Complete Electronic Resource Centre
Electronics Circuits & Tutorials

Home About us Electronic Tutorials Engineering Hobby Projects Online Dictionaries Contact us
Tutorials
  • Basic/Beginners
  • Intermediate/Advance
  • Microcontrollers
  • Microprocessors
  • Electronics Symbols
  • Electronics Formulas
  • Dictionary of Units

     more....

Dictionaries
  • Electronics Terms
  • Abbreviations
  • Computer Terms
  • Physics Glossary
  • Science Glossary
  • Space & Solar Terms
  • Semiconductor Symbols / Abbreviation
  • Radio Terminology Bibliography

     more....

Projects
  • Engineering Projects
Home > Electronics Tutorials > Online Computer Terms Dictionary > S

Online Computer Terms Dictionary - S

switch statement

<programming> (Or case statement, multi-way branch) A construct found in most high-level languages for selecting one of several possible blocks of code or branch destinations depending on the value of an expression. An example in C is

	switch (foo(x, y))
	{
	case 1:  printf("Hello\n");	/* fall through */
	case 2:  printf("Goodbye\n"); break;
	case 3:  printf("Fish\n"); break;
	default: fprintf(stderr, "Odd foo value\n"); exit(1);
	}

The break statements cause execution to continue after the whole switch statemetnt. The lack of a break statement after the first case means that execution will fall through into the second case. Since this is a common programming error you should add a comment if it is intentional.

If none of the explicit cases matches the expression value then the (optional) default case is taken.

A similar construct in some functional languages returns the value of one of several expressions selected according to the value of the first expression. A distant relation to the modern switch statement is Fortran's computed goto.

(1997-01-30)

 


Nearby terms: switched virtual circuit « switched virtual connection « switching hub « switch statement » swizzle » SWL » SWT
 

Discover
  • C/C++ Language Programming Library
  • Electronic Conversions
  • History of Electronics
  • History of Computers
  • Elec. Power Standards
  • Online Calculator and Conversions
  • Electrical Hazards - Health & Safety
  • Datasheets
  • Quick Reference links
  • Electronics Magazines
  • Career in Electronics
  • EMS Post Tracking

     more......

Home Electronic Tutorials Engineering Hobby Projects Resources Links Sitemap Disclaimer/T&C

Copyright © 1999-2020 www.hobbyprojects.com  (All rights reserved)