{"id":132699,"date":"2026-11-25T10:20:57","date_gmt":"2026-11-25T16:20:57","guid":{"rendered":"https:\/\/www.albert.io\/blog\/?p=132699"},"modified":"2026-11-25T10:20:57","modified_gmt":"2026-11-25T16:20:57","slug":"ap-computer-science-a-unit-2-cheat-sheet","status":"publish","type":"post","link":"https:\/\/www.albert.io\/blog\/ap-computer-science-a-unit-2-cheat-sheet\/","title":{"rendered":"AP\u00ae Computer Science A Unit 2 Cheat Sheet: Selection and Iteration"},"content":{"rendered":"<p>This AP CSA Unit 2 cheat sheet covers how Java programs make decisions and repeat work: Boolean expressions, if and else-if chains, compound conditions and De Morgan&#8217;s laws, while and for loops, standard algorithms, nested loops, and informal run-time analysis. Unit 2 makes up 25% to 35% of the AP\u00ae Computer Science A exam. Choose the Simple version for the essentials or the Ultimate version for every pattern, trace, and trap.<\/p>\n\n    <div class=\"cs-tab-bar\" data-cs-config=\"{&quot;postId&quot;:132685,&quot;ajaxUrl&quot;:&quot;https:\\\/\\\/www.albert.io\\\/blog\\\/wp-admin\\\/admin-ajax.php&quot;,&quot;slots&quot;:{&quot;simple&quot;:{&quot;tier&quot;:&quot;simple&quot;,&quot;lang&quot;:&quot;&quot;},&quot;ultimate&quot;:{&quot;tier&quot;:&quot;ultimate&quot;,&quot;lang&quot;:&quot;&quot;}},&quot;lang&quot;:&quot;&quot;,&quot;tier&quot;:&quot;simple&quot;}\">\n                <div class=\"cs-tabs\" role=\"tablist\">\n                            <button class=\"cs-tab cs-tab--active\"\n                        role=\"tab\"\n                        aria-selected=\"true\"\n                        data-tier=\"simple\">\n                    Simple                <\/button>\n                            <button class=\"cs-tab\"\n                        role=\"tab\"\n                        aria-selected=\"false\"\n                        data-tier=\"ultimate\">\n                    Ultimate                <\/button>\n                    <\/div>\n        <div class=\"cs-preview-area\">\n                            <div class=\"cs-preview cs-preview--active\"\n                     data-slot=\"simple\">\n                                            <img decoding=\"async\" class=\"cs-preview-img\"\n                             src=\"https:\/\/www.albert.io\/blog\/wp-content\/uploads\/2026\/11\/AP-Computer-Science-A-Unit-2-Simple-Cheat-Sheet-Preview-1.png\"\n                             alt=\"Simple cheat sheet preview\"\n                             loading=\"lazy\">\n                                    <\/div>\n                            <div class=\"cs-preview\"\n                     data-slot=\"ultimate\">\n                                            <img decoding=\"async\" class=\"cs-preview-img\"\n                             src=\"https:\/\/www.albert.io\/blog\/wp-content\/uploads\/2026\/11\/AP-Computer-Science-A-Unit-2-Ultimate-Cheat-Sheet-Preview-1.png\"\n                             alt=\"Ultimate cheat sheet preview\"\n                             loading=\"lazy\">\n                                    <\/div>\n                    <\/div>\n        <div class=\"cs-download-area\">\n                            <div class=\"cs-download-panel cs-download-panel--active\"\n                     data-slot=\"simple\"\n                     role=\"tabpanel\">\n                    <a class=\"cs-download-btn\" href=\"https:\/\/www.albert.io\/blog\/wp-content\/uploads\/2026\/11\/AP-Computer-Science-A-Unit-2-Simple-Cheat-Sheet-1.pdf\" data-slot=\"simple\" download>\n                        <svg class=\"cs-download-icon\" width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" fill=\"none\" aria-hidden=\"true\">\n                            <path d=\"M8 1v10m0 0L4.5 7.5M8 11l3.5-3.5M2 13h12\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\"\/>\n                        <\/svg>\n                        Download\n                    <\/a>\n                                            <a class=\"cs-customize-link\" href=\"https:\/\/www.albert.io\/blog\/?cheat_sheet_editor=1&#038;cs_id=132685&#038;cs_tier=simple\" data-slot=\"simple\" target=\"_blank\" rel=\"noopener\">\n                            Customize &rarr;\n                        <\/a>\n                                    <\/div>\n                            <div class=\"cs-download-panel\"\n                     data-slot=\"ultimate\"\n                     role=\"tabpanel\">\n                    <a class=\"cs-download-btn\" href=\"https:\/\/www.albert.io\/blog\/wp-content\/uploads\/2026\/11\/AP-Computer-Science-A-Unit-2-Ultimate-Cheat-Sheet-1.pdf\" data-slot=\"ultimate\" download>\n                        <svg class=\"cs-download-icon\" width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" fill=\"none\" aria-hidden=\"true\">\n                            <path d=\"M8 1v10m0 0L4.5 7.5M8 11l3.5-3.5M2 13h12\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\"\/>\n                        <\/svg>\n                        Download\n                    <\/a>\n                                            <a class=\"cs-customize-link\" href=\"https:\/\/www.albert.io\/blog\/?cheat_sheet_editor=1&#038;cs_id=132685&#038;cs_tier=ultimate\" data-slot=\"ultimate\" target=\"_blank\" rel=\"noopener\">\n                            Customize &rarr;\n                        <\/a>\n                                    <\/div>\n                    <\/div>\n    <\/div>\n    <p class=\"cs-cta-strip\"><a href=\"https:\/\/www.albert.io\/ap-computer-science-a\">Practice AP\u00ae Computer Science A Unit 2 questions on Albert <span aria-hidden=\"true\">&rarr;<\/span><\/a><\/p>\n\n\n<h2>What&#8217;s on the AP CSA Unit 2 Cheat Sheet?<\/h2>\n<p>Both versions follow Unit 2 of the College Board&#8217;s <a href=\"https:\/\/apcentral.collegeboard.org\/courses\/ap-computer-science-a\">AP Computer Science A course<\/a>. Seven cards cover the unit&#8217;s topics in order, from algorithms and Boolean expressions through nested iteration and run-time analysis, and an eighth card covers tracing and exam strategy.<\/p>\n<p><strong>The Simple version<\/strong> gives you the relational and logical operators with a truth table, if-else and else-if rules, De Morgan&#8217;s laws, the structure of while and for loops, a table for counting loop passes, the standard number and String algorithms, and how to count nested loop runs.<\/p>\n<p><strong>The Ultimate version<\/strong> adds comparing Strings and doubles safely, dangling else and missing braces, short-circuit guards, a negation table, digit and sentinel loops, step sizes and countdown loops, prime checks and substring searches, dependent inner loops, logarithmic loops, and free-response tips. Start with Simple, then move to Ultimate when you are tracing code under time pressure.<\/p>\n\n<h2>AP CSA Unit 2 at a Glance<\/h2>\n<table>\n<tr><th>Topic<\/th><th>Focus<\/th><\/tr>\n<tr><td>Algorithms with selection and repetition<\/td><td>Sequencing, selection, and iteration<\/td><\/tr>\n<tr><td>Boolean expressions<\/td><td>Relational operators and comparing values<\/td><\/tr>\n<tr><td>if statements and nested if statements<\/td><td>Choosing which code runs<\/td><\/tr>\n<tr><td>Compound Boolean expressions<\/td><td>&amp;&amp;, ||, !, short-circuit evaluation<\/td><\/tr>\n<tr><td>Comparing Boolean expressions<\/td><td>De Morgan&#8217;s laws and equivalence<\/td><\/tr>\n<tr><td>while and for loops<\/td><td>Repeating code and counting passes<\/td><\/tr>\n<tr><td>Implementing selection and iteration algorithms<\/td><td>Sums, averages, min and max, counting, digits<\/td><\/tr>\n<tr><td>Implementing String algorithms<\/td><td>Traversing, reversing, and searching Strings<\/td><\/tr>\n<tr><td>Nested iteration<\/td><td>Loops inside loops<\/td><\/tr>\n<tr><td>Informal run-time analysis<\/td><td>Counting how many times statements execute<\/td><\/tr>\n<\/table>\n<p>The AP CSA exam has 42 multiple-choice questions in 90 minutes (55% of the score) and four free-response questions in 90 minutes (45%). Unit 2 is 25% to 35% of the exam, and its loops and conditionals appear inside nearly every free-response question.<\/p>\n\n<h2>Key Concepts in Selection and Iteration<\/h2>\n\n<h3>Boolean Expressions and Comparisons<\/h3>\n<p>A Boolean expression evaluates to true or false using relational operators such as ==, !=, &lt;, and &gt;=. Use == for primitive values like int and boolean, but use equals to compare the characters in two Strings, because == only checks whether two references point to the same object. Avoid == with doubles, since rounding makes 0.1 + 0.2 == 0.3 false.<\/p>\n<p><strong>Exam tip:<\/strong> Trace a condition by plugging in values and writing T or F above each part.<\/p>\n\n<h3>if, else, and else-if Chains<\/h3>\n<p>An if statement runs its block only when the condition is true. In an if-else, exactly one block runs. In an else-if chain, Java checks conditions from top to bottom and runs only the first true branch, so the strictest test belongs first. Separate if statements, by contrast, are each checked, so several can run.<\/p>\n<p><strong>Worked example:<\/strong> With if (s &gt;= 80) grade = &#8220;B&#8221;; else if (s &gt;= 90) grade = &#8220;A&#8221;; a score of 95 receives a B, because the first true condition wins. Reversing the order fixes it.<\/p>\n<p>Watch for missing braces: without them, only the first statement after an if belongs to it, no matter how the code is indented. An else always pairs with the nearest unmatched if.<\/p>\n\n<h3>Compound Conditions and De Morgan&#8217;s Laws<\/h3>\n<p>The operators &amp;&amp; (and), || (or), and ! (not) combine conditions. Java uses short-circuit evaluation: if the left side of &amp;&amp; is false, or the left side of || is true, the right side is skipped. That lets you write guards like x != 0 &amp;&amp; 10 \/ x &gt; 2 without risking a division by zero.<\/p>\n<p>De Morgan&#8217;s laws rewrite negations: !(a &amp;&amp; b) is equivalent to !a || !b, and !(a || b) is equivalent to !a &amp;&amp; !b. When you negate a comparison, include the boundary: the opposite of x &gt; 5 is x &lt;= 5, not x &lt; 5.<\/p>\n\n<h3>while and for Loops<\/h3>\n<p>A while loop checks its condition before each pass, so it may run zero times. Every loop needs an initialization, a condition, and an update that eventually makes the condition false; forgetting the update causes an infinite loop. A for loop packs those three parts into its header and is best when you know how many passes you need.<\/p>\n<p><strong>Worked example:<\/strong> for (int i = 0; i &lt; 20; i += 5) runs with i = 0, 5, 10, and 15, so it makes 4 passes. A loop from i = a while i &lt; b with i++ runs b \u2212 a times; with i &lt;= b, it runs b \u2212 a + 1 times.<\/p>\n<p><strong>Exam tip:<\/strong> Off-by-one errors are the most common loop trap. Check the first and last values of the loop variable every time.<\/p>\n\n<h3>Standard Algorithms<\/h3>\n<p>A handful of patterns appear again and again: summing values, computing an average with a cast to double, finding a minimum or maximum, counting items that meet a condition, and extracting digits with % 10 and \/ 10. For Strings, loop from index 0 to length \u2212 1 and use substring(i, i + 1) to access each character, build a reversed String by adding each character to the front, and search with indexOf or by comparing substrings.<\/p>\n<p><strong>Exam tip:<\/strong> In a search, return true as soon as you find a match, but return false only after the loop finishes.<\/p>\n\n<h3>Nested Loops and Run-Time Analysis<\/h3>\n<p>An inner loop runs all of its passes for each pass of the outer loop, so 3 outer passes and 4 inner passes run the inner body 12 times. If the inner loop depends on the outer variable, add up each row instead: an inner loop with j &lt; i for i = 0 to 3 runs 0 + 1 + 2 + 3 = 6 times. Informal run-time analysis asks you to count how many times a statement executes, which tells you how efficient an algorithm is.<\/p>\n\n<h2>A Sample Trace<\/h2>\n<p>Consider this segment: int count = 0; for (int i = 1; i &lt;= 10; i++) { if (i % 3 == 0 || i % 5 == 0) count++; }. Build a table with columns for i, the condition, and count. The condition is true for i = 3, 5, 6, 9, and 10, so count ends at 5. Notice that 10 counts once even though only the second part of the condition is true, and that 15 is never checked because the loop stops at 10.<\/p>\n<p>Now change the condition to i % 3 == 0 &amp;&amp; i % 5 == 0. No value from 1 to 10 is divisible by both 3 and 5, so count stays 0. Questions like this test whether you read &amp;&amp; and || carefully, and they reward a quick table over mental math.<\/p>\n\n<h2>How Unit 2 Shows Up on the AP CSA Exam<\/h2>\n<p>Multiple-choice questions often show a short code segment and ask what it prints, how many times a statement runs, which Boolean expression is equivalent to another, or which loop produces a given output. Use a trace table with one column per variable and one row per pass, and look for patterns after a few passes rather than tracing every iteration.<\/p>\n<p>On the free-response section, the first question focuses on methods and control structures, and loops and conditionals appear in all four questions. Return the declared type instead of printing, use the methods the question provides, and test your code mentally with an empty String, a single element, and the last index.<\/p>\n\n<h2>Common Mistakes in AP CSA Unit 2<\/h2>\n<ol>\n<li><strong>Comparing Strings with ==.<\/strong> Fix: use equals.<\/li>\n<li><strong>Ordering an else-if chain from loosest to strictest.<\/strong> Fix: put the strictest condition first.<\/li>\n<li><strong>Negating x &gt; 5 as x &lt; 5.<\/strong> Fix: the negation is x &lt;= 5.<\/li>\n<li><strong>Looping to i &lt;= s.length().<\/strong> Fix: the last valid index is length \u2212 1.<\/li>\n<li><strong>Returning false inside the loop on the first mismatch.<\/strong> Fix: return false after the loop ends.<\/li>\n<\/ol>\n\n<h2>Frequently Asked Questions<\/h2>\n<h3>Can I use this cheat sheet on the exam?<\/h3>\n<p>No. The AP CSA exam provides only the Java Quick Reference, which lists String and Math methods. Use the cheat sheet while you practice so loop and condition patterns are automatic on test day.<\/p>\n<h3>Should I start with the Simple or the Ultimate version?<\/h3>\n<p>Start with the Simple version of the AP CSA Unit 2 cheat sheet to learn the core syntax and patterns. Move to Ultimate when you want more tracing examples and the less common traps.<\/p>\n<h3>When should I use a for loop instead of a while loop?<\/h3>\n<p>Use a for loop when you know how many passes you need, such as visiting every index of a String. Use a while loop when the loop should stop based on a condition, such as reading until a sentinel value appears.<\/p>\n<h3>What is short-circuit evaluation and why does it matter?<\/h3>\n<p>Java stops evaluating a compound condition as soon as the result is known. With &amp;&amp;, a false left side makes the whole expression false, so the right side is skipped. With ||, a true left side makes the whole expression true. This lets you place a safety check first, such as checking that an index is in range before reading a character at that index.<\/p>\n<h3>Does the Java Quick Reference help with Unit 2?<\/h3>\n<p>Only partly. It lists String methods like substring, indexOf, and equals, which you will use in String algorithms, but it does not explain loop or if syntax, operator precedence, or how to count loop passes. Those need to be memorized.<\/p>\n<h3>How do I count how many times a nested loop runs?<\/h3>\n<p>If the loops are independent, multiply the outer passes by the inner passes. If the inner loop depends on the outer variable, list the inner count for each outer value and add them up.<\/p>\n\n<section class=\"cs-footer\"><div class=\"cs-cta\"><h2 class=\"cs-cta-title\">Practice AP\u00ae Computer Science A Unit 2 on Albert<\/h2><p>A cheat sheet tells you what to know. Practice shows you whether you know it. Albert&#039;s AP\u00ae Computer Science A course has exam-style questions with a full explanation for every answer, organized by unit so you can drill exactly what this sheet covers.<\/p><a class=\"cs-cta-btn\" href=\"https:\/\/www.albert.io\/ap-computer-science-a\">Start practicing AP\u00ae Computer Science A<\/a><\/div><h2>More AP\u00ae Computer Science A cheat sheets<\/h2><nav class=\"cs-unit-nav\" aria-label=\"Previous and next AP\u00ae Computer Science A units\"><a class=\"cs-unit-prev\" rel=\"prev\" href=\"https:\/\/www.albert.io\/blog\/ap-computer-science-a-unit-1-cheat-sheet\/\"><span aria-hidden=\"true\">&larr;<\/span> Unit 1: Using Objects and Methods<\/a><a class=\"cs-unit-next\" rel=\"next\" href=\"https:\/\/www.albert.io\/blog\/ap-computer-science-a-unit-3-cheat-sheet\/\">Unit 3: Class Creation <span aria-hidden=\"true\">&rarr;<\/span><\/a><\/nav><ul class=\"cs-units-list\"><li class=\"cs-units-full\"><a href=\"https:\/\/www.albert.io\/blog\/ap-computer-science-a-cheat-sheets\/\">AP\u00ae Computer Science A full-exam cheat sheet<\/a><\/li><li><a href=\"https:\/\/www.albert.io\/blog\/ap-computer-science-a-unit-1-cheat-sheet\/\">Unit 1: Using Objects and Methods<\/a><\/li><li aria-current=\"page\"><strong>Unit 2: Selection and Iteration<\/strong><\/li><li><a href=\"https:\/\/www.albert.io\/blog\/ap-computer-science-a-unit-3-cheat-sheet\/\">Unit 3: Class Creation<\/a><\/li><li><a href=\"https:\/\/www.albert.io\/blog\/ap-computer-science-a-unit-4-cheat-sheet\/\">Unit 4: Data Collections<\/a><\/li><\/ul><p class=\"cs-calc\">See where you stand: plug your practice scores into the <a href=\"https:\/\/www.albert.io\/blog\/ap-computer-science-a-score-calculator\/\">AP\u00ae Computer Science A score calculator<\/a> to estimate your exam score.<\/p><\/section>\n\n","protected":false},"excerpt":{"rendered":"<p>Free AP CSA Unit 2 cheat sheet: Boolean logic, if statements, De Morgan&#8217;s laws, while and for loops, algorithms and nested loops, Simple and Ultimate.<\/p>\n","protected":false},"author":33,"featured_media":135899,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_lmt_disableupdate":"","_lmt_disable":"","albert_practice_url":"","albert_lit_section":"analysis","albert_lit_sort_order":0,"footnotes":""},"categories":[432,16193,5],"tags":[14030],"class_list":["post-132699","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ap-computer-science-a","category-cheat-sheets","category-test-prep","tag-cheat-sheet"],"acf":{"post_id":null},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>AP\u00ae Computer Science A Unit 2 Cheat Sheet: Selection and Iteration | Albert Blog &amp; Resources<\/title>\n<meta name=\"description\" content=\"Free AP CSA Unit 2 cheat sheet: Boolean logic, if statements, De Morgan&#039;s laws, while and for loops, algorithms and nested loops, Simple and Ultimate.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.albert.io\/blog\/ap-computer-science-a-unit-2-cheat-sheet\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"AP\u00ae Computer Science A Unit 2 Cheat Sheet: Selection and Iteration | Albert Blog &amp; Resources\" \/>\n<meta property=\"og:description\" content=\"Free AP CSA Unit 2 cheat sheet: Boolean logic, if statements, De Morgan&#039;s laws, while and for loops, algorithms and nested loops, Simple and Ultimate.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.albert.io\/blog\/ap-computer-science-a-unit-2-cheat-sheet\/\" \/>\n<meta property=\"og:site_name\" content=\"Albert Blog &amp; Resources\" \/>\n<meta property=\"article:published_time\" content=\"2026-11-25T16:20:57+00:00\" \/>\n<meta name=\"author\" content=\"Molly Cohen\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Molly Cohen\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.albert.io\/blog\/ap-computer-science-a-unit-2-cheat-sheet\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.albert.io\/blog\/ap-computer-science-a-unit-2-cheat-sheet\/\"},\"author\":{\"name\":\"Molly Cohen\",\"@id\":\"https:\/\/www.albert.io\/blog\/#\/schema\/person\/b637fa59873224c3dd2c8e47aedbda80\"},\"headline\":\"AP\u00ae Computer Science A Unit 2 Cheat Sheet: Selection and Iteration\",\"datePublished\":\"2026-11-25T16:20:57+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.albert.io\/blog\/ap-computer-science-a-unit-2-cheat-sheet\/\"},\"wordCount\":1573,\"image\":{\"@id\":\"https:\/\/www.albert.io\/blog\/ap-computer-science-a-unit-2-cheat-sheet\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.albert.io\/blog\/wp-content\/uploads\/2026\/11\/AP-Computer-Science-A-Unit-2-Ultimate-Cheat-Sheet-Preview-1.png\",\"keywords\":[\"Cheat Sheet\"],\"articleSection\":[\"AP\u00ae Computer Science A\",\"Cheat Sheets\",\"Test Prep\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.albert.io\/blog\/ap-computer-science-a-unit-2-cheat-sheet\/\",\"url\":\"https:\/\/www.albert.io\/blog\/ap-computer-science-a-unit-2-cheat-sheet\/\",\"name\":\"AP\u00ae Computer Science A Unit 2 Cheat Sheet: Selection and Iteration | Albert Blog &amp; Resources\",\"isPartOf\":{\"@id\":\"https:\/\/www.albert.io\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.albert.io\/blog\/ap-computer-science-a-unit-2-cheat-sheet\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.albert.io\/blog\/ap-computer-science-a-unit-2-cheat-sheet\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.albert.io\/blog\/wp-content\/uploads\/2026\/11\/AP-Computer-Science-A-Unit-2-Ultimate-Cheat-Sheet-Preview-1.png\",\"datePublished\":\"2026-11-25T16:20:57+00:00\",\"author\":{\"@id\":\"https:\/\/www.albert.io\/blog\/#\/schema\/person\/b637fa59873224c3dd2c8e47aedbda80\"},\"description\":\"Free AP CSA Unit 2 cheat sheet: Boolean logic, if statements, De Morgan's laws, while and for loops, algorithms and nested loops, Simple and Ultimate.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.albert.io\/blog\/ap-computer-science-a-unit-2-cheat-sheet\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.albert.io\/blog\/ap-computer-science-a-unit-2-cheat-sheet\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.albert.io\/blog\/ap-computer-science-a-unit-2-cheat-sheet\/#primaryimage\",\"url\":\"https:\/\/www.albert.io\/blog\/wp-content\/uploads\/2026\/11\/AP-Computer-Science-A-Unit-2-Ultimate-Cheat-Sheet-Preview-1.png\",\"contentUrl\":\"https:\/\/www.albert.io\/blog\/wp-content\/uploads\/2026\/11\/AP-Computer-Science-A-Unit-2-Ultimate-Cheat-Sheet-Preview-1.png\",\"width\":1600,\"height\":1237},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.albert.io\/blog\/ap-computer-science-a-unit-2-cheat-sheet\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.albert.io\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"AP\u00ae Computer Science A Unit 2 Cheat Sheet: Selection and Iteration\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.albert.io\/blog\/#website\",\"url\":\"https:\/\/www.albert.io\/blog\/\",\"name\":\"Albert Blog &amp; Resources\",\"description\":\"Free resources and practice materials for students and teachers!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.albert.io\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.albert.io\/blog\/#\/schema\/person\/b637fa59873224c3dd2c8e47aedbda80\",\"name\":\"Molly Cohen\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.albert.io\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/3f932c474f636324737023ed6ff1911d3c5b89ad205041e3401870ade4ebbb69?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/3f932c474f636324737023ed6ff1911d3c5b89ad205041e3401870ade4ebbb69?s=96&d=mm&r=g\",\"caption\":\"Molly Cohen\"},\"url\":\"https:\/\/www.albert.io\/blog\/author\/mollycohenatalbert\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"AP\u00ae Computer Science A Unit 2 Cheat Sheet: Selection and Iteration | Albert Blog &amp; Resources","description":"Free AP CSA Unit 2 cheat sheet: Boolean logic, if statements, De Morgan's laws, while and for loops, algorithms and nested loops, Simple and Ultimate.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.albert.io\/blog\/ap-computer-science-a-unit-2-cheat-sheet\/","og_locale":"en_US","og_type":"article","og_title":"AP\u00ae Computer Science A Unit 2 Cheat Sheet: Selection and Iteration | Albert Blog &amp; Resources","og_description":"Free AP CSA Unit 2 cheat sheet: Boolean logic, if statements, De Morgan's laws, while and for loops, algorithms and nested loops, Simple and Ultimate.","og_url":"https:\/\/www.albert.io\/blog\/ap-computer-science-a-unit-2-cheat-sheet\/","og_site_name":"Albert Blog &amp; Resources","article_published_time":"2026-11-25T16:20:57+00:00","author":"Molly Cohen","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Molly Cohen","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.albert.io\/blog\/ap-computer-science-a-unit-2-cheat-sheet\/#article","isPartOf":{"@id":"https:\/\/www.albert.io\/blog\/ap-computer-science-a-unit-2-cheat-sheet\/"},"author":{"name":"Molly Cohen","@id":"https:\/\/www.albert.io\/blog\/#\/schema\/person\/b637fa59873224c3dd2c8e47aedbda80"},"headline":"AP\u00ae Computer Science A Unit 2 Cheat Sheet: Selection and Iteration","datePublished":"2026-11-25T16:20:57+00:00","mainEntityOfPage":{"@id":"https:\/\/www.albert.io\/blog\/ap-computer-science-a-unit-2-cheat-sheet\/"},"wordCount":1573,"image":{"@id":"https:\/\/www.albert.io\/blog\/ap-computer-science-a-unit-2-cheat-sheet\/#primaryimage"},"thumbnailUrl":"https:\/\/www.albert.io\/blog\/wp-content\/uploads\/2026\/11\/AP-Computer-Science-A-Unit-2-Ultimate-Cheat-Sheet-Preview-1.png","keywords":["Cheat Sheet"],"articleSection":["AP\u00ae Computer Science A","Cheat Sheets","Test Prep"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.albert.io\/blog\/ap-computer-science-a-unit-2-cheat-sheet\/","url":"https:\/\/www.albert.io\/blog\/ap-computer-science-a-unit-2-cheat-sheet\/","name":"AP\u00ae Computer Science A Unit 2 Cheat Sheet: Selection and Iteration | Albert Blog &amp; Resources","isPartOf":{"@id":"https:\/\/www.albert.io\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.albert.io\/blog\/ap-computer-science-a-unit-2-cheat-sheet\/#primaryimage"},"image":{"@id":"https:\/\/www.albert.io\/blog\/ap-computer-science-a-unit-2-cheat-sheet\/#primaryimage"},"thumbnailUrl":"https:\/\/www.albert.io\/blog\/wp-content\/uploads\/2026\/11\/AP-Computer-Science-A-Unit-2-Ultimate-Cheat-Sheet-Preview-1.png","datePublished":"2026-11-25T16:20:57+00:00","author":{"@id":"https:\/\/www.albert.io\/blog\/#\/schema\/person\/b637fa59873224c3dd2c8e47aedbda80"},"description":"Free AP CSA Unit 2 cheat sheet: Boolean logic, if statements, De Morgan's laws, while and for loops, algorithms and nested loops, Simple and Ultimate.","breadcrumb":{"@id":"https:\/\/www.albert.io\/blog\/ap-computer-science-a-unit-2-cheat-sheet\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.albert.io\/blog\/ap-computer-science-a-unit-2-cheat-sheet\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.albert.io\/blog\/ap-computer-science-a-unit-2-cheat-sheet\/#primaryimage","url":"https:\/\/www.albert.io\/blog\/wp-content\/uploads\/2026\/11\/AP-Computer-Science-A-Unit-2-Ultimate-Cheat-Sheet-Preview-1.png","contentUrl":"https:\/\/www.albert.io\/blog\/wp-content\/uploads\/2026\/11\/AP-Computer-Science-A-Unit-2-Ultimate-Cheat-Sheet-Preview-1.png","width":1600,"height":1237},{"@type":"BreadcrumbList","@id":"https:\/\/www.albert.io\/blog\/ap-computer-science-a-unit-2-cheat-sheet\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.albert.io\/blog\/"},{"@type":"ListItem","position":2,"name":"AP\u00ae Computer Science A Unit 2 Cheat Sheet: Selection and Iteration"}]},{"@type":"WebSite","@id":"https:\/\/www.albert.io\/blog\/#website","url":"https:\/\/www.albert.io\/blog\/","name":"Albert Blog &amp; Resources","description":"Free resources and practice materials for students and teachers!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.albert.io\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.albert.io\/blog\/#\/schema\/person\/b637fa59873224c3dd2c8e47aedbda80","name":"Molly Cohen","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.albert.io\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/3f932c474f636324737023ed6ff1911d3c5b89ad205041e3401870ade4ebbb69?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/3f932c474f636324737023ed6ff1911d3c5b89ad205041e3401870ade4ebbb69?s=96&d=mm&r=g","caption":"Molly Cohen"},"url":"https:\/\/www.albert.io\/blog\/author\/mollycohenatalbert\/"}]}},"modified_by":null,"_links":{"self":[{"href":"https:\/\/www.albert.io\/blog\/wp-json\/wp\/v2\/posts\/132699","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.albert.io\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.albert.io\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.albert.io\/blog\/wp-json\/wp\/v2\/users\/33"}],"replies":[{"embeddable":true,"href":"https:\/\/www.albert.io\/blog\/wp-json\/wp\/v2\/comments?post=132699"}],"version-history":[{"count":1,"href":"https:\/\/www.albert.io\/blog\/wp-json\/wp\/v2\/posts\/132699\/revisions"}],"predecessor-version":[{"id":132728,"href":"https:\/\/www.albert.io\/blog\/wp-json\/wp\/v2\/posts\/132699\/revisions\/132728"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.albert.io\/blog\/wp-json\/wp\/v2\/media\/135899"}],"wp:attachment":[{"href":"https:\/\/www.albert.io\/blog\/wp-json\/wp\/v2\/media?parent=132699"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.albert.io\/blog\/wp-json\/wp\/v2\/categories?post=132699"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.albert.io\/blog\/wp-json\/wp\/v2\/tags?post=132699"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}