Skip to content

Instantly share code, notes, and snippets.

View rshepherd's full-sized avatar
💭
Building something…

Randy Shepherd rshepherd

💭
Building something…
View GitHub Profile
public class ForLoops {
public static void main(String[] args) {
// for ( init ; test ; increment ) {
// body
// }
// 1) The 'init' code runs once to set things up at the very start of the loop.
// 2) The boolean 'test' is evaluated.
@rshepherd
rshepherd / Expressions.java
Last active December 23, 2015 16:19
Expressions versus statements
public class Expressions {
public static void main(String[] args) {
// Expressions evaluate to a value...
int z = 1 + 1;
// ^^^^^
// Statements do not.
System.out.println("This is a statement.");
@rshepherd
rshepherd / BadConditionals.java
Last active December 23, 2015 16:19
What does this print?
boolean a = false;
boolean b = true;
// Example 1
if(b);
a = true;
System.out.println(a)
// Example 2
@rshepherd
rshepherd / bit_intrepretations.cpp
Last active December 23, 2015 15:29
Interpreting bit patterns as different types
#include<iostream>
using namespace std;
int main() {
//long x = 1;
long x = -1;
// A pointer to the bit pattern, interpreted as a 32-bit signed int
int* i = (int*) &x;